<template>
    <div class="main">
        <div class="login">
            <div class="login-left">
                <img style="width: 100%;margin-top: 50%;" src="../../assets/logo.png">
            </div>
            <div class="login-right">
                <div class="login-right-top">
                    <span style="margin-left: 9%;">spring-vue-admin</span>
                    <p>A management platform using Spring and Vue</p>
                </div>
                <div class="login-right-foot">
                    <div class="input-foot">
                        <div class="wave-group">
                            <input v-model="username" type="text" class="input">
                            <span class="bar"></span>
                            <label class="label">
                                <span class="label-char" style="--index: 0">用</span>
                                <span class="label-char" style="--index: 1">户</span>
                                <span class="label-char" style="--index: 2">名</span>
                            </label>
                        </div>
                        <br>
                        <div class="wave-group">
                            <input v-model="password" type="password" class="input">
                            <span class="bar"></span>
                            <label class="label">
                                <span class="label-char" style="--index: 0">密</span>
                                <span class="label-char" style="--index: 1">码</span>
                            </label>
                        </div>
                    </div>
                    <div class="button-foot">
                        <button @click="login()">
                            <div class="svg-wrapper-1">
                                <div class="svg-wrapper">
                                    <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24">
                                        <path fill="none" d="M0 0h24v24H0z"></path>
                                        <path fill="currentColor"
                                            d="M1.946 9.315c-.522-.174-.527-.455.01-.634l19.087-6.362c.529-.176.832.12.684.638l-5.454 19.086c-.15.529-.455.547-.679.045L12 14l6-8-8 6-8.054-2.685z">
                                        </path>
                                    </svg>
                                </div>
                            </div>
                            <span>登录</span>
                        </button>
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>

<script setup name="Login">
    import { ref } from 'vue'
    import { getLoginStatus } from '@/api'
    import { ElMessage } from 'element-plus';
    import router from '@/router';

    const username = ref()
    const password = ref()

    async function login() {
       let params = new URLSearchParams();
       params.append("username",username.value)
       params.append("password",password.value)
    await getLoginStatus(params)
        .then((res)=>{
            if(res.code == 1){
                localStorage.setItem('userName',username.value)
                ElMessage({
                    type: 'info',
                    message: res.msg,
                })
                router.push('/homepage')
            }else{
                ElMessage({
                    type: 'info',
                    message: res.msg,
                })
            }
        })
    }

</script>


<style scoped>
.main {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 98.3vh;
    background-color: rgb(244, 245, 247);
    min-width: 1180px;
}

.login {
    display: flex;
    flex-direction: row;
    width: 50%;
    height: 60%;
    background-color: rgb(242, 244, 245);
    border-radius: 20px;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
}

.login-left {
    width: 40%;
    height: 100%;
    background-color: rgb(238, 238, 238);
}

.login-right {
    width: 60%;
    height: 100%;
    display: flex;
    flex-direction: column;
}

.login-right-top {
    margin-top: 15%;
    margin-left: 20%;
}

.login-right-top span {
    font-size: 30px;
    font-weight: 800;
}

.login-right-foot {
    margin-top: 10%;
}


/* 输入框样式 */
/* From Uiverse.io by AbanoubMagdy1 */
.wave-group {
    position: relative;
}

.wave-group .input {
    font-size: 16px;
    padding: 10px 10px 10px 5px;
    display: block;
    width: 200px;
    border: none;
    border-bottom: 1px solid #515151;
    background: transparent;
}

.wave-group .input:focus {
    outline: none;
}

.wave-group .label {
    color: #999;
    font-size: 18px;
    font-weight: normal;
    position: absolute;
    pointer-events: none;
    left: 5px;
    top: 10px;
    display: flex;
}

.wave-group .label-char {
    transition: 0.2s ease all;
    transition-delay: calc(var(--index) * .05s);
}

.wave-group .input:focus~label .label-char,
.wave-group .input:valid~label .label-char {
    transform: translateY(-20px);
    font-size: 14px;
    color: #5264AE;
}

.wave-group .bar {
    position: relative;
    display: block;
    width: 200px;
}

.wave-group .bar:before,
.wave-group .bar:after {
    content: '';
    height: 2px;
    width: 0;
    bottom: 1px;
    position: absolute;
    background: #5264AE;
    transition: 0.2s ease all;
    -moz-transition: 0.2s ease all;
    -webkit-transition: 0.2s ease all;
}

.wave-group .bar:before {
    left: 50%;
}

.wave-group .bar:after {
    right: 50%;
}

.wave-group .input:focus~.bar:before,
.wave-group .input:focus~.bar:after {
    width: 50%;
}

.input-foot {
    margin-left: 30%;
}

/* From Uiverse.io by adamgiebl */
button {
    font-family: inherit;
    font-size: 20px;
    background: rgb(85, 116, 210);
    color: white;
    padding: 0.7em 1em;
    padding-left: 0.9em;
    display: flex;
    align-items: center;
    border: none;
    border-radius: 16px;
    overflow: hidden;
    transition: all 0.2s;
    cursor: pointer;
}

button span {
    display: block;
    margin-left: 0.3em;
    transition: all 0.3s ease-in-out;
}

button svg {
    display: block;
    transform-origin: center center;
    transition: transform 0.3s ease-in-out;
}

button:hover .svg-wrapper {
    animation: fly-1 0.6s ease-in-out infinite alternate;
}

button:hover svg {
    transform: translateX(1.2em) rotate(45deg) scale(1.1);
}

button:hover span {
    transform: translateX(5em);
}

button:active {
    transform: scale(0.95);
}

@keyframes fly-1 {
    from {
        transform: translateY(0.1em);
    }

    to {
        transform: translateY(-0.1em);
    }
}

.button-foot{
    margin-top: 5%;
    margin-left: 40%;
}

@media (max-width: 1600px) {
    .login-left {
        display: none;
    }

    .login-right {
        flex: 1;
        width: 100%;
    }
}
</style>
